local extension = Package("ldheroes")
extension.extensionName = "brokenroyal"
extension.game_modes_whitelist = {"brokenroyal_mode"}

local ld = require "packages/brokenroyal/util"
local U = require "packages/utility/utility"

local caocao = General(extension, "br__caocao", "ding", 4)

local br__guixin = fk.CreateTriggerSkill{
  name = "br__guixin",
  frequency = Skill.Compulsory,
  events = {fk.GameStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.GameStart then
      room:setPlayerMark(player, "guixin_buff", 1)
    end
  end,
}

caocao:addSkill(br__guixin)

local simayi = General(extension, "br__simayi", "ding", 4)
local br__wuchang = fk.CreateViewAsSkill{
  name = "br__wuchang",
  pattern = ".|.|.|.|.|basic|br__slash,br__jink,br__analeptic,br__grain",
  card_filter = function(self, to_select, selected)
    if #selected == 1 then return false end
    local _c = Fk:getCardById(to_select)
    local c
    if _c.name == "br__slash" then
      c = Fk:cloneCard("br__jink")
    elseif _c.name == "br__jink" then
      c = Fk:cloneCard("br__slash")
    elseif _c.name == "br__grain" then
      c = Fk:cloneCard("br__analeptic")
    elseif _c.name == "br__analeptic" then
      c = Fk:cloneCard("br__grain")
    else
      return false
    end
    return (Fk.currentResponsePattern == nil and Self:canUse(c)) or (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(c))
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local _c = Fk:getCardById(cards[1])
    local c
    if _c.name == "br__slash" then
      c = Fk:cloneCard("br__jink")
    elseif _c.name == "br__jink" then
      c = Fk:cloneCard("br__slash")
    elseif _c.name == "br__grain" then
      c = Fk:cloneCard("br__analeptic")
    elseif _c.name == "br__analeptic" then
      c = Fk:cloneCard("br__grain")
    end
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
}

simayi:addSkill(br__wuchang)

local xunyu = General(extension, "br__xunyu", "ding", 4)

local br__juxian = fk.CreateActiveSkill{
  name = "br__juxian",
  anim_type = "drawcard",
  prompt = "你可以消耗1点指令，亮出计谋区和锻造区各两张牌，你选择其中一张牌获得之",
  card_num = 0,
  target_num = 0,
  can_use = function(self, player)
    return player:getMark("instruction") > 0
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    ld.addinstruction(player, -1)
    room.logic:trigger("fk.StartDiscover", player)
    if player:getMark("@@spreadrumor-turn") ~= 0 then
      local judge = {
        who = player,
        reason = "spreadrumor",
        pattern = ".|.|spade,diamond,club",
      }
      room:judge(judge)
      local result = judge.card
      if result.suit == Card.Heart then
        return false
      end
    end
    local showcards = {}
    local ld_tricks = room:getBanner("@$tricks") or {}
    local ld_equips = room:getBanner("@$equips") or {}
    table.insertTable(showcards, table.random(ld_tricks, 2))
    table.insertTable(showcards, table.random(ld_equips, 2))
    local target = player
    if player:getMark("@@honey_trap-phase") ~= 0 then--美人计
       target = player:getNextAlive()
    end
    if #showcards > 0 then
      local get = U.askforChooseCardsAndChoice(target, showcards, {"OK"}, self.name, "请选择获得的牌")
      if #get > 0 then
        local id = get[1]
        if Fk:getCardById(id).type == Card.TypeTrick then
          ld.enterScenario(self, player, id)
          table.removeOne(showcards, id)
          room.logic:trigger("fk.EndDiscover", player, {ids = showcards})
        elseif Fk:getCardById(id).type == Card.TypeEquip then
          table.removeOne(ld_equips, id)
          table.shuffle(ld_equips)
          room:setBanner("@$equips", ld_equips)
          room:moveCardTo(id, Card.PlayerHand, player, fk.ReasonJustMove, self.name)
        end
      end
    end
  end,
}

local juxian_buff = fk.CreateTriggerSkill{
  name = "#juxian_buff",
  frequency = Skill.Compulsory,
  priority = -1,
  mute = true,
  events = {fk.GameStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:handleAddLoseSkills(player, "-DiscoverSkill&")
  end,
}

br__juxian:addRelatedSkill(juxian_buff)
xunyu:addSkill(br__juxian)

local xunyou = General(extension, "br__xunyou", "ding", 4)
local br__qice = fk.CreateViewAsSkill{
  name = "br__qice",
  pattern = ".|.|.|.|.|basic|.",
  interaction = function()
    local all_names = U.getAllCardNames("b")
    local names = U.getViewAsCardNames(Self, "br__qice", all_names)
    if #names == 0 then return false end
    return U.CardNameBox { choices = names, all_choices = all_names }
  end,
  card_filter = Util.FalseFunc,
  view_as = function(self, cards)
    if #cards ~= 0 or not self.interaction.data then return nil end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = self.name
    return card
  end,
  before_use = function (self, player, use)
    player:throwAllCards("h")
    player.room:setPlayerMark(player, "instruction", 0)
    ld.upgradelayer(player)
    player.room:addPlayerMark(player, "br__qice-turn")
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 and (player:getHandcardNum() + player:getMark("instruction")) == 4
  end,
  enabled_at_response = function(self, player, response)
    return player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 and (player:getHandcardNum() + player:getMark("instruction")) == 4
    and not response
  end,
}

local br__qice_trigger = fk.CreateTriggerSkill{
  name = "#br__qice_trigger",
  mute = true,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player:getMark("br__qice-turn") > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local ld_tricks = player.room:getBanner("@$tricks") or {}
    local ld_equips = player.room:getBanner("@$equips") or {}
    player:drawCards(1, self.name)
    if #ld_tricks > 0 then
      local cards = table.random(ld_tricks, 1)
      if #cards > 0 then
        table.removeOne(ld_tricks, cards[1])
        table.shuffle(ld_tricks)
        room:setBanner("@$tricks", ld_tricks)
        ld.enterScenario(self, player, cards[1])
      end
    end
    if #ld_equips > 0 then
      local cards = table.random(ld_equips, 1)
      if #cards > 0 then
        table.removeOne(ld_equips, cards[1])
        table.shuffle(ld_equips)
        room:setBanner("@$equips", ld_equips)
        room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonJustMove, self.name)
      end
    end
  end,
}

br__qice:addRelatedSkill(br__qice_trigger)
xunyou:addSkill(br__qice)

local zhangliao = General(extension, "br__zhangliao", "ding", 4)

local br__duorui = fk.CreateActiveSkill{
  name = "br__duorui",
  card_num = 1,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, to_select, selected, targets)
    return Fk:getCardById(to_select).trueName == "slash" and #selected == 0
  end,
  target_filter = function(self, to_select)
    return to_select ~= Self.id
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    room:moveCardTo(effect.cards, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, effect.from)
    if to:getMark("instruction") > 0 then
      ld.addinstruction(to, -1)
    end
    if to:getMark("instruction") == 0 and not to:isNude() then
      if not to:isKongcheng() then
        local ids = room:askForCardsChosen(player, to, 1, 1, "h", self.name)
        --room:moveCardTo(ids, Card.PlayerHand, player, fk.ReasonPrey, self.name, "", true, effect.from)
        room:moveCardTo(ids, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, effect.from)
      end
    end
  end,
}

zhangliao:addSkill(br__duorui)

local liubei = General(extension, "br__liubei", "ding", 4)

local br__xinghan = fk.CreateTriggerSkill{
  name = "br__xinghan",
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name) and target == player
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local judgeData = {
      who = player,
      reason = self.name,
      pattern = ".|.|heart,diamond",
    }
    room:judge(judgeData)
    if judgeData.card.color == Card.Red then
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
    end
    if judgeData.card.suit == Card.Heart then
      room:moveCardTo(judgeData.card, Card.PlayerHand, player, fk.ReasonJustMove, self.name)
    end
  end,
}

liubei:addSkill(br__xinghan)

local guanyu = General(extension, "br__guanyu", "ding", 4)

--[[local br__weizhen = fk.CreateTriggerSkill{
  name = "br__weizhen",
  frequency = Skill.Compulsory,
  events = {fk.GameStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.maxHp = player.maxHp + 1
    player.hp = player.hp + 1
    player.room:broadcastProperty(player, "maxHp")
    player.room:broadcastProperty(player, "hp")
  end,
}
]]

local br__weizhen = fk.CreateViewAsSkill{
  name = "br__weizhen",
  anim_type = "offensive",
  expand_pile = "#standby",
  pattern = ".|.|.|.|.|basic|br__slash",
  card_filter = function(self, to_select, selected)
    if #selected > 0 then return false end
    return Fk:getCardById(to_select).color == Card.Red and Fk:currentRoom():getCardArea(to_select) == Player.Hand
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local c = Fk:cloneCard("br__slash")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return Fk.currentResponsePattern == nil and c
  end,
}

local weizhen_buff = fk.CreateTriggerSkill{
  name = "#weizhen_buff",
  refresh_events = {fk.Damage},
  can_refresh = function(self, event, target, player, data)
    return target == player and data.card and data.card.name == "br__slash" and data.card.suit == Card.Heart
  end,
  on_refresh = function(self, event, target, player, data)
    ld.addinstruction(player, 1)
  end,
}

br__weizhen:addRelatedSkill(weizhen_buff)
guanyu:addSkill(br__weizhen)

local zhugeliang = General(extension, "br__zhugeliang", "ding", 4)

local br__wanji = fk.CreateTriggerSkill{
  name = "br__wanji",
  frequency = Skill.Compulsory,
  events = {fk.GameStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "extra_scenario", 1)
  end,
}

zhugeliang:addSkill(br__wanji)

local machao = General(extension, "br__machao", "ding", 4)

local br__tieqi = fk.CreateTriggerSkill{
  name = "br__tieqi",
  frequency = Skill.Limited,
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and
    data.card and data.card.name == "br__slash"
  end,
  on_use = function(self, event, target, player, data)
    player.room:addPlayerMark(data.to, "@@tieqi_buff")
  end,

  refresh_events = {fk.AfterTurnEnd},
  can_refresh = function(self, event, target, player, data)
    return target ~= player and target:getMark("@@tieqi_buff") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(target, "@@tieqi_buff", 0)
  end,
}

machao:addSkill(br__tieqi)

local huangzhong = General(extension, "br__huangzhong", "ding", 4)

local br__liegong = fk.CreateTriggerSkill{
  name = "br__liegong",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.name == "shot__slash"
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    data.disresponsive = true
    local to = room:getPlayerById(data.to)
    if to:getMark("instruction") == 0 then
      data.additionalDamage = (data.additionalDamage or 0) + 1
    end
  end,
}

local liegong_buff = fk.CreateFilterSkill{
  name = "#br__liegong_buff",
  card_filter = function(self, to_select, player)
    return player:hasSkill(self) and to_select.name == "br__slash" and to_select.color == Card.Red
  end,
  view_as = function(self, to_select)
    return Fk:cloneCard("shot__slash", to_select.suit, to_select.number)
  end,
}
br__liegong:addRelatedSkill(liegong_buff)
huangzhong:addSkill(br__liegong)

local sunquan = General(extension, "br__sunquan", "ding", 4)

local br__zhiheng = fk.CreateActiveSkill{
  name = "br__zhiheng",
  anim_type = "drawCards",
  expand_pile = "#standby",
  prompt = "你可弃置至少一张装备牌，从锻造区摸等量的牌",
  target_num = 0,
  min_card_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, to_select, selected)
    return Fk:getCardById(to_select).type == Card.TypeEquip
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    --room:throwCard(effect.cards, self.name, player)
    local ld_equips = room:getBanner("@$equips") or {} --先获取锻造区，避免摸回来
    room:moveCardTo(effect.cards, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, effect.from)
    if #ld_equips > 0 then
      local n = math.min(#ld_equips, #effect.cards)
      local cards = table.random(ld_equips, n)
      if #cards > 0 then
        for i = 1, #cards, 1 do
          table.removeOne(ld_equips, cards[i])
        end
        table.shuffle(ld_equips)
        room:setBanner("@$equips", ld_equips)
        room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonJustMove, self.name)
      end
    end
  end,
}

sunquan:addSkill(br__zhiheng)

--local sunjian = General(extension, "br__sunjian", "ding", 4)

local sunce = General(extension, "br__sunce", "ding", 4)

local br__zhicun = fk.CreateActiveSkill{
  name = "br__zhicun",
  prompt = "你可交给对手一张宝物牌，+3指令",
  target_num = 1,
  card_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).sub_type == Card.SubtypeTreasure--and Fk:currentRoom():getCardArea(to_select) == Player.Hand
  end,
  target_filter = function(self, to_select)
    return to_select ~= Self.id
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    room:moveCardTo(effect.cards, Card.PlayerHand, to, fk.ReasonPrey, self.name, "", true, effect.from)
    ld.addinstruction(player, 3)
  end,
}

sunce:addSkill(br__zhicun)

local zhouyu = General(extension, "br__zhouyu", "ding", 4)

local br__yeyan = fk.CreateActiveSkill{
  name = "br__yeyan",
  frequency = Skill.Limited,
  prompt = "你可令所有角色弃置所有手牌和装备区内的牌，然后各摸四张牌",
  target_num = 0,
  card_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    for _, to in ipairs(room.alive_players) do
      to:throwAllCards("h")
      local equips = to:getCardIds(Player.Equip)
      table.insertTable(equips, to:getPile("#standby"))
      table.insertTable(equips, to:getPile("sixdragon"))
      table.insertTable(equips, to:getPile("#scenario"))
      table.insertTable(equips, to:getPile("#scenario&"))
      if #equips > 0 then
        local dummy = Fk:cloneCard("br__jink")
        dummy:addSubcards(equips)
        room:moveCardTo(dummy, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, effect.from)
        ld.upgradelayer(to)
      end
    end
    for _, p in ipairs(room.alive_players) do
      p:drawCards(4, self.name)
    end
  end,
}

zhouyu:addSkill(br__yeyan)

local lvmeng = General(extension, "br__lvmeng", "ding", 4)
local br__baiyi = fk.CreateTriggerSkill{
  name = "br__baiyi",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return target ~= player and player:hasSkill(self.name) and player:getMark("instruction") > 0
  end,
  on_use = function(self, event, target, player, data)
    local card = player.room:getCardsFromPileByRule("plan", 1, "discardPile")
    if #card > 0 then
      player.room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonJustMove, self.name)
    else
      player:drawCards(1, self.name)
    end
  end,
}

lvmeng:addSkill(br__baiyi)

local lvbu = General(extension, "br__lvbu", "ding", 4)
local br__wushuang = fk.CreateTriggerSkill{
  name = "br__wushuang",
  frequency = Skill.Compulsory,
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self.name) and player:usedSkillTimes(self.name) == 0 then
      return data.card.trueName == "slash" and data.card.color == Card.Black
    end
  end,
  on_trigger = function(self, event, target, player, data)
    player:addCardUseHistory(data.card.trueName, -1)
  end,
}

lvbu:addSkill(br__wushuang)

local dongzhuo = General(extension, "br__dongzhuo", "ding", 4)
local br__wuyan = fk.CreateTriggerSkill{
  name = "br__wuyan",
  frequency = Skill.Compulsory,
  events = {fk.DrawNCards},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and player:getHandcardNum() <= player.hp
  end,
  on_use = function(self, event, target, player, data)
    data.n = data.n + 1
  end,
}

dongzhuo:addSkill(br__wuyan)

local yuanshao = General(extension, "br__yuanshao", "ding", 4)

local br__mouduan = fk.CreateTriggerSkill{
  name = "br__mouduan",
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and data.card.name == "plan"
  end,
  on_use = function(self, event, target, player, data)
    local ld_tricks = player.room:getBanner("@$tricks") or {}
    if #ld_tricks > 0 then
      local cards = table.random(ld_tricks, 1)
      if #cards > 0 then
        ld.enterScenario(self, player, cards[1])
      end
    end
    player.room:setPlayerMark(player, "mouduan-phase", 1)
  end,
}

yuanshao:addSkill(br__mouduan)

local diaochan = General(extension, "br__diaochan", "ding", 4, 4, General.Female)

local br__biyue = fk.CreateTriggerSkill{
  name = "br__biyue",
  frequency = Skill.Compulsory,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name)
  end,
  on_use = function(self, event, target, player, data)
    ld.addinstruction(player, 1)
  end,
}

diaochan:addSkill(br__biyue)

local jiaxu = General(extension, "br__jiaxu", "ding", 4)

local br__juece = fk.CreateActiveSkill{
  name = "br__juece",
  anim_type = "offensive",
  expand_pile = "#scenario&",
  target_num = 1,
  card_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  target_filter = function(self, to_select)
    local to = Fk:currentRoom():getPlayerById(to_select)
    return to_select ~= Self.id and (#to:getPile("#scenario&") > 0 or ld.hasEmptyScenario(to))
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Self:getPileNameOfId(to_select) == "#scenario&" and Fk:getCardById(to_select):getMark("@@trap") ~= 0
  end,
  on_use = function(self, room, effect)
    local to = room:getPlayerById(effect.tos[1])
    ld.enterScenario(self, to, effect.cards[1], true)
    if Fk:getCardById(effect.cards[1]).name ~= "baitbook" then
      local mark = to:getTableMark("invalid_replace")
      table.insertIfNeed(mark, effect.cards[1])
      room:setPlayerMark(to, "invalid_replace", mark)
    end
    --ld.addinstruction(room:getPlayerById(effect.from), 1)
  end,
}

jiaxu:addSkill(br__juece)

local george = General(extension, "br__george", "ding", 4)

local HolyGrace = fk.CreateActiveSkill{
  name = "HolyGrace",
  --frequency = Skill.Limited,
  anim_type = "big",
  expand_pile = "#standby",
  prompt = "你可横置一张装备区内的牌，此牌不能被对手获得或弃置",
  target_num = 0,
  card_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) < 2
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).type == Card.TypeEquip and Fk:currentRoom():getCardArea(to_select) ~= Player.Hand
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    if player:usedSkillTimes(self.name, Player.HistoryGame) >= 2 then
      room:setPlayerMark(player, "holygrace", {})
      local cards = player:getCardIds(Player.Equip)
      table.insertTable(cards, player:getPile("#standby"))
      for _, id in ipairs(cards) do
        room:setCardMark(Fk:getCardById(id), "@@chained", 0)
      end
    end
    local card = Fk:getCardById(effect.cards[1])
    room:setCardMark(card, "@@chained", 1)
    room:setPlayerMark(player, "holygrace", {effect.cards[1]})
    room:sendLog{
      type = "#holygrace",
      from = effect.from,
      arg = card:toLogString()
    }
  end,
}

local holymark = fk.CreateTriggerSkill{
  name = "#holymark",
  mute = true,
  refresh_events = {fk.AfterCardsMove},
  can_refresh = function(self, event, target, player, data)
    for _, move in ipairs(data) do
      if move.from and move.from == player.id then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea ~= Card.PlayerHand and table.contains(player:getTableMark("holygrace"), info.cardId) then
            return true
          end
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    for _, move in ipairs(data) do
      if move.from and move.from == player.id then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea ~= Card.PlayerHand and table.contains(player:getTableMark("holygrace"), info.cardId) then
            player.room:setPlayerMark(player, "holygrace", {})
            player.room:setCardMark(Fk:getCardById(info.cardId), "@@chained", 0)
          end
        end
      end
    end
  end,
}

HolyGrace:addRelatedSkill(holymark)
george:addSkill(HolyGrace)

local karl = General(extension, "br__karl", "ding", 4)

local searching = fk.CreateTriggerSkill{
  name = "Searching",
  frequency = Skill.Compulsory,
  events = {"fk.StartDiscover"},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "extradiscover")
  end,
}

karl:addSkill(searching)

Fk:loadTranslationTable{
    ["ldheroes"] = "裂鼎武将牌",
    ["br"] = "裂鼎",
    ["ding"] = "鼎",

    ["br__caocao"] = "曹操",
    ["#br__caocao"] = "孤行问世",
    ["designer:br__caocao"] = "伶",
    ["cv:br__caocao"] = "淼龙",
    ["br__guixin"] = "天下归心",
    [":br__guixin"] = "你的指令上限为10。",
    ["$br__guixin"] = "骖驾六龙饮玉浆，河水尽，不东流。",

    ["br__simayi"] = "司马懿",
    ["#br__simayi"] = "洛水无声",
    ["designer:br__simayi"] = "伶",
    ["cv:br__simayi"] = "淼龙",
    ["br__wuchang"] = "无常冢虎",
    [":br__wuchang"] = "你可将【杀】和【防】、【药】和【粮】相互转化。",
    ["$br__wuchang"] = "夫处世之道，亦即应变之术，岂可偏执一端？",

    ["br__xunyu"] = "荀彧",
    ["#br__xunyu"] = "君远香留",
    ["designer:br__xunyu"] = "氯",
    ["br__juxian"] = "明以举贤",
    [":br__juxian"] = "此技能替换发现：出牌阶段，你可消耗1点指令，亮出计谋区和锻造区各两张牌，你选择其中一张牌获得之。",

    ["br__xunyou"] = "荀攸",
    ["#br__xunyou"] = "策佚名传",
    ["designer:br__xunyou"] = "氯驹",
    ["br__qice"] = "十二奇策",
    [":br__qice"] = "每回合一次，若你的手牌数和指令之和为4，你可弃置所有手牌并消耗所有指令，视为使用一张指令牌，此回合结束后，你从每个牌堆摸一张牌。",

    ["br__zhangliao"] = "张辽",
    ["#br__zhangliao"] = "逍遥止啼",
    ["designer:br__zhangliao"] = "氯",
    ["br__duorui"] = "万军夺锐",
    [":br__duorui"] = "阶段技，你可弃置一张【杀】或【射】，令对手减1点指令，然后若其没有指令，则你弃置其一张手牌。",

    ["$br__duorui"] = "力慑孙仲谋，威震逍遥津。",

    ["br__liubei"] = "刘备",
    ["#br__liubei"] = "赤问九霄",
    ["designer:br__liubei"] = "伶",
    ["cv:br__liubei"] = "玖镜辰砂",
    ["br__xinghan"] = "复兴汉室",
    [":br__xinghan"] = "回合开始时，你可进行一次判定，若为<b><font color=\"#DC143C\">红色</font></b>，则你国力+1，若为<b><font color=\"#FF4433\">红桃</font></b>，你获得之。",
    ["$br__xinghan"] = "炎刘搏天争一变，定鼎九州龙归海。",

    ["br__guanyu"] = "关羽",
    ["br__weizhen"] = "威震华夏",
    [":br__weizhen"] = "你可将一张红色手牌当【杀】使用，你使用红桃【杀】造成伤害后指令+1。",
    ["$br__weizhen1"] = "关羽在此，尔等受死！",
    ["$br__weizhen2"] = "看尔乃插标卖首！",

    ["br__zhugeliang"] = "诸葛亮",
    ["#br__zhugeliang"] = "不坠青云",
    ["designer:br__zhugeliang"] = "伶",
    ["cv:br__zhugeliang"] = "淼龙",
    ["br__wanji"] = "日理万机",
    [":br__wanji"] = "游戏开始时，你将一个备用栏改为方案栏，你的方针持续回合改为8回合。",
    ["$br__wanji"] = "天衍四九，我为余一。",

    ["br__machao"] = "马超",
    ["#br__machao"] = "神威天将军",
    ["designer:br__machao"] = "氯",
    ["br__tieqi"] = "铁骑振威",
    [":br__tieqi"] = "每局限一次，当你使用【杀】造成伤害后，你可令对手下回合开始时不回复指令。",
    ["$br__tieqi"] = "敌人阵型已乱，随我杀！",
    ["@@tieqi_buff"] = "<b><font color=\"#DC143C\">铁骑</font></b>",

    ["br__huangzhong"] = "黄忠",
    ["#br__huangzhong"] = "矍铄推锋",
    ["designer:br__huangzhong"] = "伶&氯",
    ["br__liegong"] = "没金饮羽",
    [":br__liegong"] = "锁定技，你的红色【杀】视为【射】；你使用【射】不可被响应，若对手没有指令，则造成伤害+1。",
    ["#br__liegong_buff"] = "没金饮羽",

    ["br__sunquan"] = "孙权",
    ["designer:br__sunquan"] = "伶",
    ["br__zhiheng"] = "纵横捭阖",
    [":br__zhiheng"] = "出牌阶段限一次，你可弃置至少一张装备牌，从锻造区摸等量的其他牌。",
    ["$br__zhiheng"] = "纵横捭阖，自有制衡之道。",

    ["br__sunce"] = "孙策",
    ["designer:br__sunce"] = "伶",
    ["br__zhicun"] = "志存高远",
    [":br__zhicun"] = "出牌阶段限一次，你可将一张宝物牌交给对手，然后你指令+3。",
    ["$br__zhicun"] = "我的霸业，才刚刚开始。",

    ["br__zhouyu"] = "周瑜",
    ["designer:br__zhouyu"] = "伶",
    ["cv:br__zhouyu"] = "王者荣耀",
    ["br__yeyan"] = "天下两分",
    [":br__yeyan"] = "每局限一次，出牌阶段，你可令所有角色弃置手牌区和场上所有牌，然后各摸四张牌。",
    ["$br__yeyan"] = "弹指间，灰飞烟灭！",

    ["br__lvmeng"] = "吕蒙",
    ["designer:br__lvmeng"] = "氯",
    ["br__baiyi"] = "白衣渡江",
    [":br__baiyi"] = "对手的回合结束时，若你有指令，则你可从弃牌堆获得一张【计】，若无法获得，则你摸一张牌。",
    ["$br__baiyi"] = "手不释卷，学而广益。",

    ["br__sunjian"] = "孙坚",

    ["br__lvbu"] = "吕布",
    ["#br__lvbu"] = "鬼神",
    ["cv:br__lvbu"] = "淼龙",
    ["designer:br__lvbu"] = "伶",
    ["br__wushuang"] = "天下无双",
    [":br__wushuang"] = "每回合一次，你使用黑色【杀】时，令之不计入次数限制。",
    ["$br__wushuang"] = "此身此武，天下无双！",

    ["br__dongzhuo"] = "董卓",
    ["designer:br__dongzhuo"] = "伶",
    ["br__wuyan"] = "志欲无厌",
    [":br__wuyan"] = "摸牌阶段，若你的手牌数不大于体力值，则你额外摸一张牌。",
    ["$br__wuyan"] = "我还要更多，更多！",

    ["br__yuanshao"] = "袁绍",
    ["designer:br__yuanshao"] = "伶",
    ["cv:br__yuanshao"] = "淼龙",
    ["br__mouduan"] = "好谋无断",
    [":br__mouduan"] = "你使用【计】后，可从计谋区摸一张牌，本阶段你使用的下一张计谋牌的消耗指令视为1。",
    ["$br__mouduan"] = "卿等所言皆善，究竟如何是好？",

    ["br__jiaxu"] = "贾诩",
    ["designer:br__jiaxu"] = "伶",
    ["br__juece"] = "算无遗策",
    [":br__juece"] = "出牌阶段限一次，你可将一张毒计置于对手的方案区（若其方案区满，其须替换一张背面向上的计谋牌）。",

    ["br__diaochan"] = "貂蝉",
    ["designer:br__diaochan"] = "伶",
    ["cv:br__diaochan"] = "王者荣耀",
    ["br__biyue"] = "闭月绝姿",
    [":br__biyue"] = "回合结束时，你指令+1。",
    ["$br__biyue"] = "弦鼓为谁歌，旋舞因何转。",

    ["br__george"] = "乔治",
    ["designer:br__george"] = "伶",
    ["cv:br__george"] = "淼龙",
    [":HolyGrace"] = "每局限两次，出牌阶段，你可横置一张装备区内的牌，此牌不能被对手获得或弃置。第二次横置会重置第一次横置的牌。",
    ["$HolyGrace"] = "圣光啊，庇佑我吧！",
    ["#holygrace"] = "%from 横置了装备区内的 %arg",

    ["br__karl"] = "卡尔",
    ["designer:br__karl"] = "伶",
    --["cv:br__karl"] = "王者荣耀",
    [":Searching"] = "你发现牌时，额外观看一张牌。",
    --["$Searching"] = "命运无端，抉择在我。",

  }

return extension